package org.jsets.fastboot.oss.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jsets.fastboot.oss.model.dto.OutsideQuery;
import org.jsets.fastboot.oss.model.entity.Outside;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Mapper
public interface OutsideMapper extends BaseMapper<Outside> {

	@Update("update sys_file_outside t set t.status = 1 where id = #{id}")
	int updateDisableStatus(@Param("id")Long id);
	
	@Select( "<script>"
	       + "  select  "
	       + "  t.id,t.file_id,t.path,t.create_time,t.due_time,t.require_auth,t.period,t.status  "
	       + "  ,m.name as file_name  "
	       + "  ,m.bucket_name  "
	       + "  from sys_file_outside t  "
	       + "  join sys_file_meta m on t.file_id = m.id  "
	       + "  <where>  "
	       + "    <if test='criteria.fileName != null and criteria.fileName != \"\"'>  "
	       + "      m.name like concat('%',#{criteria.fileName},'%')  "
	       + "    </if>  "
	       + "    <if test='criteria.bucketName != null and criteria.bucketName != \"\"'>  "
	       + "      m.bucket_name like concat('%',#{criteria.bucketName},'%')  "
	       + "    </if>  "
	       + "    <if test='criteria.status != null'>  "
	       + "      t.status = #{criteria.status}  "
	       + "    </if>  "
	       + "  </where>  "
	       + "  order by t.create_time desc  "
	       + "</script>  ")
	List<Outside> selectPage(Page<Outside> page, @Param("criteria") OutsideQuery criteria);
}
